package org.seven.jrdp.web.mgt.sys;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import org.seven.jrdp.biz.sys.model.SysDict;
import org.seven.jrdp.biz.sys.service.SysDictService;
import org.seven.jrdp.commons.model.Option;
import org.seven.jrdp.commons.model.Result;

@RestController
@RequestMapping("/mgt/sys/dict")
public class SysDictController {
	@Autowired
	private SysDictService sysDictService;

	@GetMapping("/{view}")
	public ModelAndView view(@PathVariable String view) {
		return new ModelAndView("mgt/sys/dict/dict_" + view);
	}

	@PostMapping("/find")
	public List<SysDict> find(String type) {
		List<SysDict> list = sysDictService.find(type);
		return list;
	}

	@RequestMapping("/get")
	public SysDict get(String id) {
		SysDict sysDict = sysDictService.get(id);
		return sysDict;
	}

	@PostMapping("/insert")
	public Result insert(SysDict sysDict) {
		sysDictService.insert(sysDict);
		return Result.SUCCESS;
	}

	@PostMapping("/update")
	public Result update(SysDict sysDict) {
		sysDictService.update(sysDict);
		return Result.SUCCESS;
	}

	@PostMapping("/delete")
	public Result delete(String id) {
		sysDictService.delete(id);
		return Result.SUCCESS;
	}

	@RequestMapping("/option/{type}")
	public List<Option> option(@PathVariable String type) {
		List<Option> list = sysDictService.findOption(type);
		return list;
	}

	@RequestMapping("/text/{type}")
	public List<Option> text(@PathVariable String type) {
		List<Option> list = sysDictService.findText(type);
		return list;
	}
	
	@RequestMapping("/value/{type}")
	public List<Option> value(@PathVariable String type) {
		List<Option> list = sysDictService.findValue(type);
		return list;
	}
}